var a = getApp(), t = require("../../utils/icon.js"), e = require("../../utils/point.js"), i = require("../../utils/scrollx.js");

Page({
    data: {
        imgUrls: [ "http://fang-oss.haozu.com/cms/index/2018/04/17/sRS6YK6pM7.jpg@750w_490h_1e_1c" ],
        building: {},
        rents: [],
        gxlist: [],
        zblist: [],
        mapUrl: "",
        total: 0,
        currIndex: 1,
        tel_phone: "",
        isUp: !0,
        showYK: !1,
        shade: !1,
        subsucc: !1,
        hasError: !1,
        resPhone: "",
        isYK: !1,
        isSC: !1,
        seeWidth: 0,
        ulen: 300,
        moveCurr: 0,
        share: 0,
        shareimg: t.fenxiang,
        xingimg: t.xing,
        mapimg: t.mapimg,
        zhankai: t.zhankai,
        rightmore: t.rightmore,
        heart: t.heart,
        heart_red: t.heart_red,
        error_icon: t.error,
        close: t.close
    },
    showAll: function() {
        this.setData({
            isUp: !1
        });
    },
    changeCur: function(a) {
        this.setData({
            currIndex: a.detail.current + 1
        });
    },
    toMapInfo: function() {
        var a = this.data.building;
        wx.navigateTo({
            url: "/pages/map/map?name=" + a.name + "&address=" + a.address + "&lat=" + a.lat + "&lng=" + a.lng
        });
    },
    onLoad: function(t) {
        if (console.log(t), t.scene) {
            var i = decodeURIComponent(t.scene).split("&"), s = {
                type: i[0],
                id: i[1],
                phone: i[2]
            };
            t.building_id = s.id;
        }
        var n = this;
        n.setData({
            share: t.share ? t.share : 0,
            tel_phone: a.globalData["tel-phone"]
        });
        var r = a.getSecret(), u = a.globalData.userInfo || {};
        u && u.mobile && n.setData({
            isDis: !0,
            resPhone: u.mobile,
            loginYK: !1,
            isYK: !0
        }), wx.request({
            url: a.globalData.haozuBase + "/api/miniapps/detail/",
            data: {
                building_id: t.building_id,
                mobile: u.mobile || "",
                user_guid: u.user_guid || "",
                currtime: r.currtime,
                sign: r.sign,
                uuid: wx.getStorageSync("first_code")
            },
            success: function(t) {
                var i = t.data;
                if (200 === i.code) {
                    var s = i.data.buildingInfo;
                    i.data.employeeInfo;
                    n.setData({
                        building: s,
                        imgUrls: s.image_list,
                        rents: i.data.rentHouseList,
                        gxlist: i.data.gxHouseList,
                        total: s.image_list ? s.image_list.length : 0,
                        consultant: i.data.employeeInfo
                    }), e.getPoint({
                        lat: s.lat,
                        lng: s.lng
                    }).then(function(t) {
                        n.setData({
                            txpoint: t,
                            mapUrl: "http://apis.map.qq.com/ws/staticmap/v2/?center=" + t.lat + "," + t.lng + "&zoom=15&size=750*400&maptype=roadmap&markers=size:large|color:0xFFCCFF|label:H|" + t.lat + "," + t.lng + "&key=" + a.globalData.tencentMapKey
                        });
                    }), a.orderDisabled(n, n.data.building.id, "building_id");
                    var r = {
                        district_name: "",
                        thumb_image: "",
                        subway_display: "",
                        status: "",
                        circle_name: "",
                        tag_list: []
                    };
                    for (var u in r) r[u] = s[u];
                    r.building_name = s.name, r.subway_display = s.subway[0], r.area_min = s.areaMin, 
                    r.area_max = s.areaMax, r.price = s.priceMin, r.price_unit = s.priceUnit, r.type = 1, 
                    r.status = 0, r.building_id = s.id;
                    var d = {
                        t: 1,
                        v: s.id,
                        c: s.city_id,
                        d: s.district_id,
                        ci: s.circle_id,
                        s: s.street_id,
                        vt: new Date().getTime()
                    };
                    a.saveStorage(d, r);
                }
                1 == n.data.building.isCollect && n.setData({
                    isSC: !0
                });
            }
        }), wx.request({
            url: a.globalData.haozuBase + "/api/miniapps/likebuilding/",
            data: {
                building_id: t.building_id,
                currtime: r.currtime,
                sign: r.sign
            },
            success: function(a) {
                var t = a.data;
                200 == t.code && n.setData({
                    zblist: t.data
                });
            }
        });
    },
    onShareAppMessage: function(a) {
        var t = this;
        return {
            title: t.data.building.name,
            desc: t.data.building.address,
            path: "/pages/building/building?share=1&building_id=" + t.data.building.id
        };
    },
    onReady: function(a) {
        var t = this, e = wx.createSelectorQuery();
        e.select(".head_swiper").boundingClientRect(), e.exec(function(a) {
            var e = a[0].width;
            t.setData({
                seeWidth: e - 30 * e / 750
            });
        });
    },
    touchStart: i.touchStart,
    touchEnd: function(a) {
        i.touchEnd.call(this, a), i.goFun.call(this, a);
    },
    turnScroll: i.turnScroll,
    turnEnd: function(a) {
        i.goFun.call(this, a);
    },
    showyekan: function(a) {
        this.setData({
            shade: !0,
            showYK: !0
        });
    },
    closeyuekan: function(a) {
        this.setData({
            shade: !1,
            showYK: !1
        });
    },
    inputChange: function(a) {
        this.setData({
            resPhone: a.detail.value
        });
    },
    submitYK: function(t) {
        var e = this, i = /^(13[0-9]|14[5|7]|15[0-9]|17[0|1|3|5|6|7|8]|18[0-9])\d{8}$/, s = e.data.resPhone;
        return !e.data.isYK && (i.test(s) ? (e.setData({
            hasError: !1
        }), void a.orderlogin({
            mobile: s,
            name: "小程序楼盘页预约",
            building_id: e.data.building.id,
            building_name: e.data.building.name,
            from_page: 2
        }).then(function(a) {
            200 == a.code && (e.setData({
                showYK: !1,
                subsucc: !0,
                isYK: !0
            }), setTimeout(function() {
                e.setData({
                    shade: !1,
                    subsucc: !1
                });
            }, 3e3));
        })) : (e.setData({
            hasError: !0
        }), !1));
    },
    shouchang: function(t) {
        var e = this, i = a.globalData.userInfo || {};
        if (a.globalData.userInfo) {
            var s = a.getSecret();
            e.data.isSC ? wx.request({
                url: a.globalData.uchaozuBase + "/api/miniapps/collect/del/",
                data: {
                    uid: i.user_id || "",
                    type: "1",
                    opt_id: e.data.building.id,
                    currtime: s.currtime,
                    sign: s.sign
                },
                success: function(a) {
                    a.data;
                    if (500 === a.statusCode) return !1;
                    e.setData({
                        isSC: !1
                    });
                }
            }) : wx.request({
                url: a.globalData.uchaozuBase + "/api/miniapps/collect/add/",
                data: {
                    uid: i.user_id || "",
                    type: "1",
                    opt_id: e.data.building.id,
                    currtime: s.currtime,
                    sign: s.sign
                },
                success: function(a) {
                    a.data;
                    if (500 === a.statusCode) return !1;
                    e.setData({
                        isSC: !0
                    });
                }
            });
        } else wx.setStorage({
            key: "dataInfo",
            data: {
                uid: i.user_id || "",
                type: "1",
                opt_id: e.data.building.id
            }
        }), wx.navigateTo({
            url: "/pages/getinfo/index"
        });
    },
    zixun: function() {
        wx.makePhoneCall({
            phoneNumber: this.data.consultant.telephone
        });
    },
    xixika: function(a) {
        var t = [];
        t.push(a.currentTarget.dataset.id), wx.previewImage({
            current: a.currentTarget.dataset.id,
            urls: t
        });
    },
    zhizhao: function(a) {
        var t = [];
        t.push(a.currentTarget.dataset.id), wx.previewImage({
            current: a.currentTarget.dataset.id,
            urls: t
        });
    }
});